| Total Complexity | 3 | 
| Total Lines | 26 | 
| Duplicated Lines | 0 % | 
| Changes | 0 | ||
| 1 | import {CommandHandler} from '@nestjs/cqrs'; | 
            ||
| 8 | |||
| 9 | @CommandHandler(UpdateTaskCommand)  | 
            ||
| 10 | export class UpdateTaskCommandHandler { | 
            ||
| 11 | constructor(  | 
            ||
| 12 |     @Inject('ITaskRepository') | 
            ||
| 13 | private readonly taskRepository: ITaskRepository,  | 
            ||
| 14 | private readonly isTaskAlreadyExist: IsTaskAlreadyExist  | 
            ||
| 15 |   ) {} | 
            ||
| 16 | |||
| 17 |   public async execute(command: UpdateTaskCommand): Promise<void> { | 
            ||
| 18 |     const {id, name} = command; | 
            ||
| 19 | |||
| 20 | const task = await this.taskRepository.findOneById(id);  | 
            ||
| 21 |     if (!task) { | 
            ||
| 22 | throw new TaskNotFoundException();  | 
            ||
| 23 | }  | 
            ||
| 24 | |||
| 25 | if (  | 
            ||
| 26 | name !== task.getName() &&  | 
            ||
| 27 | true === (await this.isTaskAlreadyExist.isSatisfiedBy(name))  | 
            ||
| 28 |     ) { | 
            ||
| 29 | throw new TaskAlreadyExistException();  | 
            ||
| 30 | }  | 
            ||
| 31 | |||
| 32 | task.updateName(name);  | 
            ||
| 33 | await this.taskRepository.save(task);  | 
            ||
| 34 | }  | 
            ||
| 36 |